<template>
  <div>
    <h1>参数管理</h1>
    <el-form :inline="true" :model="queryParam" class="demo-form-inline">
      <el-form-item label="参数名称">
        <el-input v-model="queryParam.name" placeholder="参数名称"></el-input>
      </el-form-item>
      <el-form-item label="参数键名">
        <el-input v-model="queryParam.keyName" placeholder="参数键名"></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="开始日期" value-format="yyyy-MM-dd" v-model="queryParam.t1" style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker type="date" placeholder="结束日期" value-format="yyyy-MM-dd" v-model="queryParam.t2" style="width: 100%;"></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list">搜索</el-button><br>
      </el-form-item>
    </el-form>
    <el-button @click="openAdd" type="primary">添加</el-button>
    <el-button @click="delAll" type="danger">删除</el-button>
    <el-button @click="daochu" type="success">导出</el-button>
    <el-button @click="updateAll" type="warning">修改</el-button>

    <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        @selection-change="handleSelectionChange"
    >
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="id"
          label="id"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="参数名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="keyName"
          label="参数键名">
      </el-table-column>
      <el-table-column
          prop="keyValue"
          label="参数键值">
      </el-table-column>
      <el-table-column
          prop="systems"
          label="系统内置">
      </el-table-column>
      <el-table-column
          prop="remark"
          label="备注">
      </el-table-column>
      、<el-table-column
        prop="times"
        label="创建时间">
    </el-table-column>
      <el-table-column label="操作">
        <template v-slot="s">
          <el-button @click="delByUpdate(s.row.id)" type="text" >删除</el-button>
          <el-button @click="openupdates(s.row)" type="text" >修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="handleCurrentChange"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>

    <el-dialog title="修改" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="参数名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="参数键名" :label-width="formLabelWidth">
          <el-input v-model="form.keyName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="参数键值" :label-width="formLabelWidth">
          <el-input v-model="form.keyValue" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="系统内置" :label-width="formLabelWidth">
          <el-input v-model="form.systems" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input v-model="form.remark" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" :label-width="formLabelWidth">
          <el-input v-model="form.times" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="update">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="添加" :visible.sync="dialogFormVisible1">
      <el-form :model="form1">
        <el-form-item label="参数名称" :label-width="formLabelWidth1">
          <el-input v-model="form1.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="参数键名" :label-width="formLabelWidth1">
          <el-input v-model="form1.keyName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="参数键值" :label-width="formLabelWidth1">
          <el-input v-model="form1.keyValue" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="系统内置" :label-width="formLabelWidth1">
          <el-input v-model="form1.systems" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth1">
          <el-input v-model="form1.remark" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" :label-width="formLabelWidth1">
          <el-date-picker type="date" placeholder="创建时间" value-format="yyyy-MM-dd" v-model="form1.times" style="width: 100%;"></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {API} from "@/api/config";

export default {
  name: "ParamView",
  data() {
    return {
      tableData:{},
      queryParam:{},
      current:1,
      size:2,
      total:0,
      dialogFormVisible:false,
      formLabelWidth:'120px',
      formLabelWidth1:'120px',
      dialogFormVisible1:false,
      form:{},
      form1:{},
      ids:[]

    }
  }, methods: {
    handleSelectionChange(rows){
      this.ids=rows.map(item =>item.id).join(",");
      console.log(this.ids)
    },
    handleCurrentChange(current){
      this.current=current;
      this.list();
    },
    list(){
      this.axios.post("/param/list?current="+this.current+"&size="+this.size,this.queryParam).then(r =>{
        this.tableData=r.data.data.list;
        this.total=r.data.data.total;
      })
    },
    delByUpdate(id){
      this.axios.post("/param/delByUpdate?id="+id).then(() =>{
        this.$message.success("删除成功");
      })
    },
    openupdates(row){
      this.form=row;
      this.dialogFormVisible=true;
    },
    update(){
      this.axios.post("/param/updates",this.form).then(() =>{
        this.$message.success("修改成功");
        this.dialogFormVisible=false;
        this.list();
      })
    },
    openAdd(){
      this.dialogFormVisible1=true;
    },
    add(){
      this.axios.post("/param/add",this.form1).then(() =>{
        this.$message.success("添加成功");
        this.dialogFormVisible1=false;
        this.list();
      })
    },
    delAll(){
      this.axios.post("/param/dellAll?ids="+this.ids).then(() =>{
        this.$message.success("删除成功");
        this.list();
      })
    },
    daochu(){
      window.location.href=API+"/param/daochu"
    },
    updateAll(){
      this.dialogFormVisible=true;
      this.axios.post("/param/getById?id="+this.ids).then(r =>{
        console.log(r)
        this.form=r.data.data;
      })
    }
  }, created() {
    this.list();
  }
}
</script>

<style scoped>

</style>